import { Loading } from "element-ui";

let loading;
let loadingNum = 0;
const startLoading = (url) => {
  loadingNum++;
  console.log('loading start:', loadingNum)
  if (loading) {
    loading.close();
  }
  let dialog = document.getElementsByClassName('el-dialog__wrapper');
  let loadingConfig = {
    lock: true, //同v-loading的修饰符
    text: "玩命加载中...", //加载文案
    background: "rgba(0, 0, 0, 0.05)", //背景色
    spinner: "el-icon-loading", //加载图标
  }
  loading = Loading.service(loadingConfig);
};

const endLoading = () => {
  loadingNum--;
  if (loadingNum <= 0) {
    setTimeout(() => {
      loading.close();
    }, 300)
  }
};

export {
  startLoading,
  endLoading
};
